Category Archives: Linux

How to Solve Error Sudo: sorry, you must have a tty to run sudo

A few days ago, a problem was encountered. Calling another shell in a terminal was always unenforceable. Later, the wrong information was captured as sudo: sorry, you must have a TTY to run sudo, and later, it was learned online that the following can be solved:

1. Edit/etc/sudoers

1) defaults requirement is changed to “defaults requirement”, which means that the control terminal is not required.

2) defaults requirement, modify to Defaults:nobody !requiretty Indicates that only nobody users do not need to control the terminal.

If it is modified to defaults: nobody! Requirement, it means that only the nobody group does not need to control the terminal.

In fact, just comment out the defaults requirement. Indicates that the terminal is not opened during execution. However, some shells must have a terminal to execute. This is obviously not going to work. Later, I found another piece of article. The following is transcribed for future use only.

Some programs/scripts may be executed in the environment without controlling the terminal (for example, when the system starts the service, the program started by daemon,
or setsid, etc.), but this program may need to control the terminal. How about this?
for example, we start a service when Linux starts, But there is a program in the middle (the old systemtap) that uses sudo
but sudo needs to control the terminal (of course, you can modify sudo’s configuration file, but it’s not friendly to users)
example: (the program started by setsid will lose control of the terminal)
# setsid sudo LS
sudo: sorry, you must have a TTY to run sudo
(if your system doesn’t output this sentence, That is, the sudo configuration file of your system allows sudo to open the control terminal when there is no control interrupt:
# set Sid head – C 0/dev/TTY
head: cannot open ‘/ dev/TTY’ for reading: no such device or address
to solve this problem, So you should use the program that can create (pseudo) control terminal to start your program, such as: script, expect
such as:
# setsid script – C “sudo LS)/dev/null
or:
# setsid expect – C ‘SPAD sudo LS; expect’
# open the control terminal successfully:
# setsid script – C ‘head – C 0/dev/TTY’/dev/null
# setsid expect – C ‘SPAD head – C 0/dev/TTY; expect’
However, there is a strange bug in the combination of setsid and script. I’ve been using a lot of decompression during this period.
this is overqualified for script and expect.

Centos7.4 appears Yum command not found [How to Solve]

The purchased ECS runs the yum command, and the yum command not found appears.

By uninstalling Yum and python from the virtual machine, you need to pay attention to the first line of the/usr/bin/Yum file. I define it as “#!/usr/bin/Python”

1. Uninstall Python:

1 rpm -qa|grep python|xargs rpm -e --allmatches --nodeps
2 whereis python|xargs rm -fr

2. Uninstall Yum:

1 rpm -qa|grep yum|xargs rpm -e --allmatches --nodeps
2 rm -rf /etc/yum.repos.d/*
3 whereis yum|xargs rm -fr

3. Create directory Python and Yum to store RPM package:

1 mkdir /usr/local/src/python
2 mkdir /usr/local/src/yum

4. Use WGet to download the RPM package of Python and Yum respectively (Note: it must correspond to the version number of the system)

(1) Download the RPM package of Python:

1 #cd /usr/local/src/python 
2 
3 #wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-2.7.5-34.el7.x86_64.rpm
4 #wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm
5 #wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-pycurl-7.19.0-17.el7.x86_64.rpm
6 #wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-devel-2.7.5-34.el7.x86_64.rpm
7 #wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-libs-2.7.5-34.el7.x86_64.rpm
8 #wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-urlgrabber-3.10-7.el7.noarch.rpm
9 #wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/rpm-python-4.11.3-17.el7.x86_64.rpm

(2) Download RPM package from Yum:

1 #cd /usr/local/src/yum 
2 
3 #wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/yum-3.4.3-132.el7.centos.0.1.noarch.rpm
4 #wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
5 #wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-34.el7.noarch.rpm

5. Install the RPM package of Python and yum

(1) Install Python:

1 #cd /usr/local/src/python 
2 
3 #rpm -ivh python-* rpm-python-* 
4   Dependency problems with the installation package occur, at which point the following solution can be found.
5 
6 #rpm -ivh python-* rpm-python-* --nodeps --force
7 --nodeps --force is to force installation regardless of dependencies.
8 
9 Once installed, you can run python:

(2) Install Yum:

1 #cd /usr/local/src/yum 
2 #rpm -ivh yum-*

CentOS8 Install redis-6.0.6 make test:“ You need tcl 8.5 or newer in order to run the Redis test“

Installing redis-6.0.6 under centos8

Refer to redis-6.0.6

Download, unzip and compile redis

$ wget http://download.redis.io/releases/redis-6.0.6.tar.gz
$ tar xzf redis-6.0.6.tar.gz
$ cd redis-6.0.6
$ make

Enter the decompressed SRC directory and start redis with the following command:

$ src/redis-server

You can use the built-in client to interact with redis

$ src/redis-cli
redis&> set foo bar
OK
redis&> get foo
"bar"

Make test test redis-6.0.6

When testing redis, there was a problem:

[root@etcd3 src]# make test
You need tcl 8.5 or newer in order to run the Redis test
make: *** [test] Error 1

Install 8.5 or the latest TCL:

[root@etcd3 tmp]# wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz
[root@etcd3 tmp]# tar xzvf tcl8.6.1-src.tar.gz  -C /usr/local/
[root@etcd3 tmp]# cd  /usr/local/tcl8.6.1/unix/
[root@etcd3 unix]# ./configure
[root@etcd3 unix]# make
[root@etcd3 unix]# make isntall

re-run redis test: [root@etcd3 src]# make test

[root@etcd3 src]# make test
...

\o/ All tests passed without errors!

Cleanup: may take some time... OK

CentOS 7: How to install OpenOffice and Swftool

install OpenOffice

Download it from OpenOffice website: http://download.openoffice.org/all_ rc.html#untested -full ;

Enter the directory where the downloaded OpenOffice installation package is located, and then execute the command to unzip the installation package to get the directory zh CN

tar -zxv -f Apache_OpenOffice_4.0.1_Linux_x86_install-rpm_zh-CN.tar.gz (Specifically see the name of the downloaded file)

Enter the directory zh CN, and then enter the directory RPMs. Execute the following command to install all components of OpenOffice. RPM will install RPM packages according to the dependency order of RPM packages

rpm -ivh *.rpm

After the component is installed, the OpenOffice desktop integration program is installed and the installation file directory is entered

cd /opt/zh-CN/RPMS/desktop-integration

Inside is the RPM package of OpenOffice desktop integration program for four different Linux operating system distributions. Therefore, install the installation package suitable for RedHat and execute the following command to install it

rpm -ivh openoffice4.0-redhat-menus-4.0-9714.noarch.rpm

Execute the following command to start in the background

nohup /opt/openoffice4/program/soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard &

Use the command to check whether the port 8100 is occupied by sOffice, and the installation is successful.

netstat -lnp |grep 8100

Install swftools

Installing GCC + +

yum -y install make gcc gcc-c++ kernel-devel m4 ncurses-devel openssl-devel

Download swftools-0.9.2 tar.gz And unzip the installation, execute the following command

tar -xzvf swftools-0.9.2.tar.gz
cd swftools-0.9.2
./configure --prefix=/usr/local/swfTools(This is the specified installation path, if there is no such directory to new key, otherwise the installation is not successful)
make install

Installation may encounter the following problems

Problems may be encountered 1.
modules/.././types.h:39:2: error: #error "no way to define 64 bit integer"
modules/.././types.h:42:2: error: #error "don't know how to define 32 bit integer"
modules/.././types.h:45:2: error: #error "don't know how to define 16 bit integer"
modules/.././types.h:48:2: error: #error "don't know how to define 8 bit integer"
How to Solve:
[root~]# ldconfig /usr/local/lib
[root~]# ldconfig /usr/local/lib
[root~]# ./configure

Problems may be encountered 2:
rm -f /usr/local/swfTools/share/swftools/swfs/default_viewer.swf -o -L /usr/local/swfTools/share/swftools/swfs/default_viewer.swf
rm:No use -- o
Try 'rm --help' for more information.
make[1]: *** [install] error 1
make[1]: out of the floder“/opt/swftools-0.9.2/swfs”
make: *** [install] error 2
How to Solve:
Use find . / |xargs grep -r -i "default_viewer" to filter out the corresponding problem file, that is, the Makefile and Makefile.in files in the swfs directory, and remove the -o -L places in the two files.

Problem 3 may be encountered.
make[1]: Entering directory `/opt/swftools-0.9.2/swfs'
/bin/sh ../mkinstalldirs /usr/local/swfTools/share/swftools
/bin/sh ../mkinstalldirs /usr/local/swfTools/share/swftools/swfs
/usr/bin/install -c -m 644 ./simple_viewer.swf /usr/local/swfTools/share/swftools/swfs/simple_viewer.swf
/usr/bin/install: cannot stat ‘./simple_viewer.swf’: No such file or directory
make[1]: *** [install] Error 1
make[1]: Leaving directory `/opt/swftools-0.9.2/swfs'
make: *** [install] Error 2
Solution: Download the installation package again, the corresponding folder of the installation package here can not find the corresponding simple_viewer.swf file

Set environment variables and take effect

vim /etc/profile
export PATH=$PATH:/usr/swftools/bin/(/usr/swftools/bin/ is the bin directory corresponding to your swftools installation)
source /etc/profile (configure environment variables to take effect)

Download Xpdf China- simplified.tar.gz And font.zip

##Unzip the corresponding file
tar -zxvf xpdf-chinese-simplified.tar.gz
unzip font.zip
mv xpdf-chinese-simplified /usr/local

##Copy the font file to the corresponding folder to prevent messy code
mv Gbsn00lp.ttf gkai00mp.ttf /usr/local/xpdf-chinese-simplified/CMap/

Modify configuration file

cd /usr/local/xpdf-chinese-simplified
vim add-to-xpdfrc
##Add a line and change the font path above.
displayCIDFontTT        Adobe-GB1       /usr/local/xpdf-chinese-simplified/CMap/gkai00mp.ttf

The test was successful

pdf2swf -s languagedir=/usr/local/xpdf-chinese-simplified -T 9 -s poly2bitmap -s zoom=150 -s flashversion=9 "/opt/123.pdf" -o "/opt/test/%.swf"

Linux: apt get install build essential and Yum groupinstall “development tools”

Ubuntu’s apt install build essential

Function: to configure the Debian system compilation environment is to download and install the dependencies/packages that support the compilation of Debian packages, such as GCC.

Direct execution

#apt install build-essential

You can view log/var/log/apt after execution/ history.log , see the following.

Start-Date: 2019-06-08  07:54:24
Commandline: apt install build-essential
Requested-By: satou (1000)
Install: libmpc3:amd64 (1.1.0-1, automatic), libgcc-7-dev:amd64 (7.4.0-1ubuntu1~18.04, automatic), libmpx2:amd64 (8.3.0-6ubuntu1~18.04, automatic), linux-libc-dev:amd64 (4.15.0-51.55, automatic), libfakeroot:amd64 (1.22-2ubuntu1, automatic), libc6-dev:amd64 (2.27-3ubuntu1, automatic), cpp-7:amd64 (7.4.0-1ubuntu1~18.04, automatic), libalgorithm-diff-perl:amd64 (1.19.03-1, automatic), libalgorithm-merge-perl:amd64 (0.08-3, automatic), binutils:amd64 (2.30-21ubuntu1~18.04.1, automatic), cpp:amd64 (4:7.4.0-1ubuntu2.2, automatic), libitm1:amd64 (8.3.0-6ubuntu1~18.04, automatic), g++:amd64 (4:7.4.0-1ubuntu2.2, automatic), gcc-7-base:amd64 (7.4.0-1ubuntu1~18.04, automatic), gcc:amd64 (4:7.4.0-1ubuntu2.2, automatic), libcilkrts5:amd64 (7.4.0-1ubuntu1~18.04, automatic), libasan4:amd64 (7.4.0-1ubuntu1~18.04, automatic), libquadmath0:amd64 (8.3.0-6ubuntu1~18.04, automatic), libisl19:amd64 (0.19-1, automatic), build-essential:amd64 (12.4ubuntu1), libfile-fcntllock-perl:amd64 (0.22-3build2, automatic), binutils-x86-64-linux-gnu:amd64 (2.30-21ubuntu1~18.04.1, automatic), libstdc++-7-dev:amd64 (7.4.0-1ubuntu1~18.04, automatic), libtsan0:amd64 (8.3.0-6ubuntu1~18.04, automatic), libubsan0:amd64 (7.4.0-1ubuntu1~18.04, automatic), g++-7:amd64 (7.4.0-1ubuntu1~18.04, automatic), make:amd64 (4.1-9.1ubuntu1, automatic), fakeroot:amd64 (1.22-2ubuntu1, automatic), gcc-7:amd64 (7.4.0-1ubuntu1~18.04, automatic), liblsan0:amd64 (8.3.0-6ubuntu1~18.04, automatic), libgomp1:amd64 (8.3.0-6ubuntu1~18.04, automatic), manpages-dev:amd64 (4.15-1, automatic), binutils-common:amd64 (2.30-21ubuntu1~18.04.1, automatic), libc-dev-bin:amd64 (2.27-3ubuntu1, automatic), libbinutils:amd64 (2.30-21ubuntu1~18.04.1, automatic), libatomic1:amd64 (8.3.0-6ubuntu1~18.04, automatic), libcc1-0:amd64 (8.3.0-6ubuntu1~18.04, automatic), libdpkg-perl:amd64 (1.19.0.5ubuntu2.1, automatic), libalgorithm-diff-xs-perl:amd64 (0.04-5, automatic), dpkg-dev:amd64 (1.19.0.5ubuntu2.1, automatic)
Upgrade: gcc-8-base:amd64 (8.2.0-1ubuntu2~18.04, 8.3.0-6ubuntu1~18.04), libgcc1:amd64 (1:8.2.0-1ubuntu2~18.04, 1:8.3.0-6ubuntu1~18.04), libstdc++6:amd64 (8.2.0-1ubuntu2~18.04, 8.3.0-6ubuntu1~18.04)
End-Date: 2019-06-08  07:55:01

Note: (1) execute apt get update or apt update to update the package index before running, otherwise it may fail. (2) It is suggested to use apt instead of apt get

CentOS’s Yum - y groupinstall "development tools"

Function: to configure the compilation environment of CentOS is to download and install the package/dependency that enables CentOS to compile the source code package on the platform

You can use the command Yum grouplist to check which groups there are. Development tools is in available groups.

[root@localhost ~]# yum grouplist
Loaded plugins: fastestmirror, langpacks
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.tuna.tsinghua.edu.cn
Available Environment Groups:
   Minimal Install
   Compute Node
   Infrastructure Server
   File and Print Server
   Basic Web Server
   Virtualization Host
   Server with GUI
   GNOME Desktop
   KDE Plasma Workspaces
   Development and Creative Workstation
Available Groups:
   Compatibility Libraries
   Console Internet Tools
   <span style="color: red;"&><Development Tools</span&>
   Graphical Administration Tools
   Legacy UNIX Compatibility
   Scientific Support
   Security Tools
   Smart Card Support
   System Administration Tools
   System Management
Done

Before executing Yum groupinstall "development tools" , execute Yum clean all to clear Yum cache and force Yum to read some configuration files again

[root@localghost ~]# yum clean all
Loaded plugins: fastestmirror, priorities, remove-with-leaves
Cleaning up Everything
Cleaning up list of fastest mirrors
[root@localghost ~]#

List of dependency packages included in the content tools

bison
byacc
cscope
ctags
cvs
diffstat
doxygen
flex
gcc
gcc-c++
gcc-gfortran
gettext
git
indent
intltool
libtool
patch
patchutils
rcs
redhat-rpm-config
rpm-build
subversion
swig
systemtap

Perform the demo

[root@localghost ~]# yum groupinstall "Development tools"


Install      86 Package(s)
Upgrade       0 Package(s)

Total download size: 77 M
Installed size: 234 M
Is this ok [y/N]:

Enter y to confirm the installation and N to cancel. Or Yum - y groupinstall "development tools" confirm in advance.

If you encounter the following error no packages in any requested group available to install or update , you need to configure the data source

cd /etc/yum.repos.d
sudo wget http://public-yum.oracle.com/public-yum-el5.repo
cd /etc/pki/rpm-gpg/
sudo wget https://public-yum.oracle.com/RPM-GPG-KEY-oracle-el5

Reference article

https://support.eapps.com/index.php?/Knowledgebase/Article/View/438/55/user -guide—installing-the-centos-development-tools-gcc-flex-etc

Expand

Lamp one click installation – in fact, with docker container technology, I feel that lamp (Linux + Apache + MySQL/MariaDB/percona + PHP) production environment is unnecessary

Functions of Yum clean all

Functions of Yum clean all

Today, I found a machine/var &> 70%. I checked the/var/cache/Yum directory.

Use Yum clean all to clear, which is very convenient and avoids the problem of no root permission.

The function of this command is to clear the yum cache.

yum stores downloaded packages and headers in the cache and does not delete them automatically. If you think it takes up disk space, you can use the yum clean command to clear it. A more precise usage is yum clean headers to clear the headers, yum clean packages to clear the downloaded rpm packages, and yum clean all to clear them all.