Skip to content
Snippets Groups Projects
linux.md 10.9 KiB
Newer Older
  • Learn to ignore specific revisions
  • ines mkacher's avatar
    ines mkacher committed
    ## Gestion de fichiers 
    
    
    ines mkacher's avatar
    ines mkacher committed
    kill : laisse le temps au processus de ce terminer 
    
    ines mkacher's avatar
    ines mkacher committed
    
    
    ines mkacher's avatar
    ines mkacher committed
    kill -9 : tue le processus immediatement 
    
    kill -1 : signup  6-> redemarrage pour une mise à jour (relire la config) = service apache2 reload
    
    
    systemd gestion de service et de processus
    est un demon il monitore tous les processus
    upstart  /etc/init
    sysv    /etc/init.d
    
    lrwxrwxrwx 1 root root       20 avril  8 12:51 init -> /lib/systemd/systemd
    
    root@MaarchIntegration1904:/sbin# systemctl status apache2
    ● apache2.service - The Apache HTTP Server
       Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
       Active: active (running) since Fri 2019-05-03 10:17:39 CEST; 3 months 18 days ago
     Main PID: 31742 (apache2)
        Tasks: 55 (limit: 4915)
       CGroup: /system.slice/apache2.service
               ├─31742 /usr/sbin/apache2 -k start
               ├─31744 /usr/sbin/apache2 -k start
               └─31745 /usr/sbin/apache2 -k start
    
    Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.
    
    si besoin d'édition :
    
    root@MaarchIntegration1904:/etc/systemd/system# ls -ltr
    total 36
    drwxr-xr-x 2 root root 4096 nov.  13  2017 systemd-udevd.service.d
    drwxr-xr-x 2 root root 4096 nov.  13  2017 paths.target.wants
    drwxr-xr-x 2 root root 4096 nov.  13  2017 network-online.target.wants
    lrwxrwxrwx 1 root root   35 nov.  13  2017 syslog.service -> /lib/systemd/system/rsyslog.service
    lrwxrwxrwx 1 root root   31 nov.  13  2017 sshd.service -> /lib/systemd/system/ssh.service
    drwxr-xr-x 2 root root 4096 nov.  13  2017 getty.target.wants
    drwxr-xr-x 2 root root 4096 nov.  13  2017 sysinit.target.wants
    drwxr-xr-x 2 root root 4096 avril  3  2018 timers.target.wants
    drwxr-xr-x 2 root root 4096 juil.  1 11:50 sockets.target.wants
    drwxr-xr-x 2 root root 4096 juil.  1 11:50 remote-fs.target.wants
    drwxr-xr-x 2 root root 4096 juil.  1 11:50 multi-user.target.wants
    
    paramètres par defauts installées
    
    root@MaarchIntegration1904:/etc/default# ls -ltr
    total 88
    -rw-r--r-- 1 root root  306 juin   2  2015 networking
    -rw-r--r-- 1 root root 2062 déc.  30  2015 rsync
    -rw-r--r-- 1 root root  346 sept. 20  2016 acpid
    -rw-r--r-- 1 root root  222 oct.  25  2016 bsdmainutils
    -rw-r--r-- 1 root root  632 déc.  15  2016 nfs-kernel-server
    -rw-r--r-- 1 root root  793 déc.  15  2016 nfs-common
    -rw-r--r-- 1 root root  339 déc.  23  2016 autofs
    -rw-r--r-- 1 root root  124 janv. 18  2017 rsyslog
    -rw-r--r-- 1 root root  657 mars  22  2017 hwclock
    -rw-r--r-- 1 root root 1118 mai   17  2017 useradd
    -rw------- 1 root root  384 juin  15  2017 cacerts
    -rw-r--r-- 1 root root 1756 juin  15  2017 nss
    -rw-r--r-- 1 root root  133 juin  18  2017 ssh
    -rw-r--r-- 1 root root  297 juil. 30  2017 dbus
    -rw-r--r-- 1 root root  556 sept. 19  2017 apache-htcacheclean
    -rw-r--r-- 1 root root  955 oct.   7  2017 cron
    -rw-r--r-- 1 root root 1373 nov.  13  2017 grub
    -rw-r--r-- 1 root root 1228 nov.  13  2017 grub.ucf-dist
    -rw-r--r-- 1 root root  931 nov.  13  2017 irqbalance
    -rw-r--r-- 1 root root   17 avril  3  2018 locale
    -rw-r--r-- 1 root root 1014 sept. 25  2018 exim4
    -rw-r--r-- 1 root root 2006 mai    3 10:05 gandi
    
    apache /httpd (centos/debian)
    
    root@MaarchIntegration1904:/var/spool/mail# kill -l
     1) SIGHUP       2) SIGINT       3) SIGQUIT      4) SIGILL       5) SIGTRAP
     6) SIGABRT      7) SIGBUS       8) SIGFPE       9) SIGKILL     10) SIGUSR1
    11) SIGSEGV     12) SIGUSR2     13) SIGPIPE     14) SIGALRM     15) SIGTERM
    16) SIGSTKFLT   17) SIGCHLD     18) SIGCONT     19) SIGSTOP     20) SIGTSTP
    21) SIGTTIN     22) SIGTTOU     23) SIGURG      24) SIGXCPU     25) SIGXFSZ
    26) SIGVTALRM   27) SIGPROF     28) SIGWINCH    29) SIGIO       30) SIGPWR
    31) SIGSYS      34) SIGRTMIN    35) SIGRTMIN+1  36) SIGRTMIN+2  37) SIGRTMIN+3
    38) SIGRTMIN+4  39) SIGRTMIN+5  40) SIGRTMIN+6  41) SIGRTMIN+7  42) SIGRTMIN+8
    43) SIGRTMIN+9  44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
    48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
    53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9  56) SIGRTMAX-8  57) SIGRTMAX-7
    58) SIGRTMAX-6  59) SIGRTMAX-5  60) SIGRTMAX-4  61) SIGRTMAX-3  62) SIGRTMAX-2
    63) SIGRTMAX-1  64) SIGRTMAX
    root@MaarchIntegration1904:/var
    
     systemctl status apache2
     
      systemctl daemon reload si on a modifié systemd et u'on veut qu'il prenne en compte 
     
    verification des process
    
    ```
    root@MaarchIntegration1904:/var/spool/mail# ps -faux
    USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
    root         2  0.0  0.0      0     0 ?        S    mai03   0:00 [kthreadd]
    root         3  0.0  0.0      0     0 ?        S    mai03   0:28  \_ [ksoftirqd/0]
    root         5  0.0  0.0      0     0 ?        S<   mai03   0:00  \_ [kworker/0:0H]
    root         7  0.0  0.0      0     0 ?        S    mai03  44:38  \_ [rcu_sched]
    root         8  0.0  0.0      0     0 ?        S    mai03   0:00  \_ [rcu_bh]
    root         9  0.0  0.0      0     0 ?        S    mai03   0:08  \_ [migration/0]
    ```
    
    ines mkacher's avatar
    ines mkacher committed
    107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492
    
    ### Création de fichiers en doublons pour autoimport par exemple
    
    ```
    for (( i=1 ; i<=1000 ; i++ )); do cp /in/courrier/tessi_videocodage/import/C_0.pdf /in/courrier/tessi_videocodage/import/C_0$i.pdf; done
    ```
    
    
    
    ### Copier 1 fichier dans n répertoires
    
    ```
     for i in $(ls); do cp sourcefile $i; done
    ```
    
       autre exemple : 
    
    ```
     for i in $(ls); do cp post-commit $i"/hooks"; done
    ```
    
    ### Copier une liste de répertoires importante
    
    ```
    ls -1 /home/maarch/source | xargs -i cp -R /home/maarch/source/{} /home/maarch/destination
    ```
    
    
    
    ### Supprimer tous les répertoires .svn
    
    ```
    find . -name ".svn" -type d -exec rm -Rf {} \;
    ```
    
    
    
    ### Rechercher un répertoire
    
    ```
    find / -type d -name 'httpdocs'
    ```
    
    
    
    ### Recherche des fichiers plus vieux de 10 jours
    
    ```
    find /srv/backups/gandibackups_from_scp -maxdepth 1 -type f  -atime +10
    ```
    
    ### Rechercher les derniers fichiers modifiés 
    
    ```
    find /var/www/html/oem/  -not -path '*.svn/*' -mmin -120
    ```
    
    ou
    
    ```
    find /mydir -type f -mtime -1 -print
    ```
    
      
    
    ### Recherche une chaine de caractère sur tout le système
    
    ```
    cd /
    grep -r 'laurent.giovannoni@maarch.org' * > result_search
    ```
    
    
    
    ### Suppression de fichier ou de répertoire avec liste d'exclusion depuis ls
    
    ```
    rm -Rf $(ls | grep -v 'wordpress\|phpmyadmin')
    ```
    
    
    
    ### Compter le nombre d'éléments dans un répertoire
    
    ```
    ls -Al /home/maarch/source | wc -l
    ```
    
    
    
    ### Compter le nombre de fichiers XML dans un répertoire et ses sous-répertoires :
    
    ```
    find /opt/maarch/imports/autoimport/CGR_REPRISE_COMPTA -name '*.xml' | wc
    ```
    
    
    
    ### Remplacer des caractères (tokens) dans plusieurs fichiers  
    
    ```
    sed -i -e "s/PASSWORD_MAIL_DSAF/lemotdepasse\!test/g" *.XML
    ```
    
    
    
    ### Remplacer du texte dans une série de fichiers répartis dans des dossiers
    
    ```
    find /var/www/html -type f -exec sed -i 's/5432/5434/g' {} \;
    ```
    
    
    
    ### liste des fichiers créer
    
    il y a moins de 12 jours, exclusion de l'extension .cache et du répertoire www/maarch.com/*
    
    ```
    sudo find www/ -type f  \( ! -iname "*.cache" ! -iname "*.pyc" ! -iname "*.png" ! -path "www/maarch.com/*"  ! -path "www/demo.maarch.org/entreprise_*" ! -path "www/demo.maarch.org/cilbox/*" \)  -atime -1  > result
    
    sudo find www/ -type f   -atime -5  > result
    ```
    
    
    
    ### Liste des fichiers avec juste la taille (format lisible) et le nom
    
    ```
    ls -lh | awk '{print $5, $9}'
    ```
    
    
    
    ## Compression et décompression
    
    ### création d'un tar.gz
    
    ```
       tar -zcvf votre_archive.tar.gz votre_dossier/
    ```
    
    
    
    ### Décompresser un tar.gz
    
    ```
       tar -zxvf votre_archive.tar.gz -C votre_dossier_cible/
    ```
    
    
    
    ### Extraire un fichier spécifique d'un tar.gz
    
    ```
    	tar -zxvf indexes_20180429T203402.tar.gz "indexes/45" 
    ```
    
    
    
    ### Compression 7z
    
    ```
    7z a -y -mx -t7z zz-Archives.7z zz-Archives/
    ```
    
    
    
    ### unzip odt
    
    ```
    zip -0 -X ../my-document.odt
    zip odt
    zip -r ../my-document.odt * -x mimetype
    ```
    
    
    
    ## Réseaux
    
    ### liste des ports utilisés :
    
    ```
    netstat -ntlp | grep LISTEN
    ```
    
    
    
    ### Les processus écoutant sur un port  
    
    ```
    lsof -i:4444 -> 
    ```
    
    
    
    ### redémarrer réseau
    
    ```
    sudo ifdown -a
    
    sudo ifup -a
    
    sudo dhclient
    
    sudo start network-manager
    
    sudo /etc/init.d/network-manager restart
    ```
    
    
    
    
    
    ## Configuration de PHP
    
    ------
    
    Configuration et switch de versions
    
    ### #switch to php7.1
    
    ```
    sudo a2dismod php5.6
    sudo a2enmod php7.1
    sudo service apache2 restart
    sudo mv /usr/bin/php /usr/bin/php_BAK
    sudo rm /usr/bin/php
    sudo ln -s /usr/bin/php7.1 /usr/bin/php 
    ```
    
    
    
    ### #switch to php7
    
    ```
    sudo a2dismod php5.6
    sudo a2enmod php7.0
    sudo service apache2 restart
    ```
    
    
    
    ### #switch to php5.6
    
    ```
    sudo a2dismod php7.1
    sudo a2enmod php5.6
    sudo service apache2 restart
    sudo mv /usr/bin/php /usr/bin/php_BAK
    sudo rm /usr/bin/php
    sudo ln -s /usr/bin/php5.6 /usr/bin/php
    ```
    
    ## Increase size of request in apache for REST webservices
    
    ```
    #LimitRequestFields 32767
    #LimitRequestFieldSize 12392
    LimitRequestLine 10000000000000000
    ```
    
    
    
    ## Docker 
    
    ### Liste des images locales
    
    ```
    docker images
    ```
    
    ### Lancer la construction de dockerfile
    
    ```
    docker build . -t maarchcourrier
    ```
    
    ### Lancer sh pour un container 
    
    ```
    docker exec -it  maarchcourrier-develop /bin/bash
    ```
    
    
    
    ## PostgreSQL
    
    ### Supprimer toutes les sockets ouvertes par apache pour postgres
    
    ```
    netstat -anp | grep --regexp="5432" | grep apache2 |  awk -F" " '{print $7}' | awk -F"/" '{print $1}'
    
    echo kill $(sudo netstat -anp | grep --regexp="5432" | grep apache2 |  awk -F" " '{print $7}' | awk -F"/" '{print $1}')
    ```
    
    
    
    ### Créer un cluster postgres
    
    ```
    su - 
    mkdir /opt/postgtresql
    chown -R postgres. /opt/postgtresql
    su postgres
    /usr/lib/postgresql/11/bin/initdb -D /opt/postgtresql
    
    #Succès. Vous pouvez maintenant lancer le serveur de bases de données en utilisant :
    cd /opt/postgresql
    ```
    
    
    
    ### Créer un fichier de trace
    
    ```
    /usr/lib/postgresql/11/bin/pg_ctl -D /opt/postgtresql -l fichier_de_trace start
    ```
    
    
    
    ## Autres
    
    ### Exécuter plusieurs fois le même fichier php
    
    ```
    for (( i=1 ; i<=10 ; i++ )); do php test_ws_store_resource.php; done
    ```
    
    ### Liste des paquets installés 
    
    ```
    sudo dpkg-query -l | grep xdebug
    ```
    
    ### Tuer tous les processus d'un utilisateur
    
    ```
    ps -aef | grep  ^www-data | awk '{ print "kill -9 " $2 }' | sh
    ```
    
    ### Signer une applet java avec un certificat 
    
    ```
    openssl pkcs12 -in ~/OS201403208071.pfx -out mypenfile.pem
    
    openssl pkcs12 -export -in mypenfile.pem -out mykeystore.p12 -name "MyCert"
    
    jarsigner -storepass MaarchCertif2014 -tsa http://timestamp.globalsign.com/scripts/timestamp.dll-storetype pkcs12 -keystore mykeystore.p12 NetBeansProjects/maarchCM/dist/maarchCM.jar "MyCert"
    
    cd /home/lgi/NetBeansProjects
    jarsigner  -storepass MaarchCertif2014  -keystore ../mykeystore.p12 -tsa http://timestamp.globalsign.com/scripts/timestamp.dll ../NetBeansProjects/maarchCM/dist/maarchCM.jar "mydomain"
    ```
    
    
    
    ### Vérifier la langues
    
    ```
    dpkg-reconfigure locales
    ```
    
    ## 
    
    ### Convertir un pdf en imagette png thumbnails
    
    ```
    convert -thumbnail 800x1200 -background white -alpha remove install/samples/res_attachments/invitation.pdf install/samples/tnl/invitation.png
    ```
    
    
    
    ### Gestion de wikijs
    
    lancement
    
    ```
    node wiki start
    ```
    
    arrêt
    
    ```
    node wiki stop
    ```